package com.zx.mes.senior.string;

import org.junit.Test;

/**
 * 字符串进行一些没试
 * @author huayunlong
 * @date 2018-7-23
 */
public class StringTest {

    @Test
    public void test(){
        String a = "a" + "b" + 1;
        String b = "ab1";
        /// 实则比较栈上内容是否一致,8种基本类型的值是直接在栈上的,对象是在堆上,所以栈上比较地址
        System.out.println(a==b);
        /// Object 默认equals实现就是==
        System.out.println(a.equals(b));
    }

    @Test
    public void test2(){
        /// 局部变量不会被JVM优化
        String a = "a";
        final String c = "a";
        String b = a + "b";
        String d = c + "b";
        String e = getA() + "b";
        String compare = "ab";
        System.out.println(b==compare);
        System.out.println(d==compare);
        System.out.println(e==compare);
    }


    public String getA() {
        return "a";
    }
}
